package com.zmn.plat.services.impl.channel;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.common.dto.KVDTO;
import com.zmn.plat.model.entity.channel.ChannelServiceArea;
import com.zmn.plat.model.entity.channel.ChannelServiceAreaQuery;
import com.zmn.plat.persistence.interfaces.channel.ChannelServiceAreaDAO;
import com.zmn.plat.services.interfaces.channel.ChannelServiceAreaService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * 渠道服务区域
 *
 * @author xiangjunming
 * @since 2019/08/19 12:18:09
 */
@Service
public class ChannelServiceAreaServiceImpl implements ChannelServiceAreaService {

    @Resource
    private ChannelServiceAreaDAO channelServiceAreaDAO;

    @Override
    public ChannelServiceArea findByKey(Integer id) {
        return channelServiceAreaDAO.findByKey(id);
    }

    @Override
    public List<ChannelServiceArea> listByChannelId(Integer channelId) {
        return channelServiceAreaDAO.listByChannelId(channelId);
    }

    @Override
    public List<ChannelServiceArea> listCountryIsNull(Integer channelId, List<Integer> cityIds) {
        return channelServiceAreaDAO.listCountryIsNull(channelId, cityIds);
    }

    @Override
    public List<ChannelServiceArea> listByChannelIdAndCityIds(Integer channelId, List<Integer> cityIds) {
        return channelServiceAreaDAO.listByChannelIdAndCityIds(channelId, cityIds);
    }

    @Override
    public List<ChannelServiceArea> listByChannelIdAndCountryIds(Integer channelId, List<Integer> countryIds) {
        return channelServiceAreaDAO.listByChannelIdAndCountryIds(channelId, countryIds);
    }

    @Override
    public List<ChannelServiceArea> listPageByQuery(ChannelServiceAreaQuery query) {
        int countTotal = channelServiceAreaDAO.countByQuery(query);
        Optional.ofNullable(query).ifPresent(p -> query.setTotalCount(countTotal));
        return channelServiceAreaDAO.listPageByQuery(query);
    }

    @Override
    public List<ChannelServiceArea> listCityByChannelId(Integer channelId) {
        return channelServiceAreaDAO.listCityByChannelId(channelId);
    }

    @Override
    public int updateByKey(ChannelServiceArea record) {
        record.setUpdateTime(DateUtil.getNow());
        return channelServiceAreaDAO.updateByKey(record);
    }

    @Override
    public int updateBatch(String updater, List<Integer> serviceAreaIds) {
        return channelServiceAreaDAO.updateBatch(updater, serviceAreaIds);
    }

    @Override
    public int insert(ChannelServiceArea record) {
        record.setCreateTime(DateUtil.getNow());
        return channelServiceAreaDAO.insert(record);
    }

    @Override
    public int insertBatch(List<ChannelServiceArea> list) {
        return channelServiceAreaDAO.insertBatch(list);
    }

    @Override
    public int deleteByKey(Integer id) {
        return channelServiceAreaDAO.deleteByKey(id);
    }

    @Override
    public int deleteByKeys(List<Integer> ids) {
        return channelServiceAreaDAO.deleteByKeys(ids);
    }

    @Override
    public Integer deleteByChannelId(Integer channelId) {
        return channelServiceAreaDAO.deleteByChannelId(channelId);
    }

    @Override
    public void copy(Integer originalChannelId, int targetChannelId, String operator) {

        channelServiceAreaDAO.copy(originalChannelId, targetChannelId, operator);
    }
}